<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="(item, index1) in page" :key="index1">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.iconUrl" alt="">
          </div>
          <p class="icon-desc">
            {{item.desc}}
          </p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>
<script>
export default {
  data () {
    return {
      swiperOption: {
        // 指定那个元素容器 作为页面指示页
        pagination: '.swiper-pagination',
        /* 让小圆点 有切换页码的功能 */
        paginationClickable: true
      },
      iconLists: [
        {
          id: '100001',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '景点门票',
        },
        {
          id: '100002',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '一日游',
        },
        {
          id: '100003',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '郑州必游',
        },
        {
          id: '100004',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '夏日玩水',
        },
        {
          id: '100005',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '名胜古迹',
        }, {
          id: '100006',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '景点门票',
        },
        {
          id: '100007',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '一日游',
        },
        {
          id: '100008',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '郑州必游',
        },
        {
          id: '100009',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '夏日玩水',
        },
        {
          id: '1000010',
          iconUrl:'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '名胜古迹',
        }
      ]
    }
  },
  computed: {
    pages() {
      const pages =[];
      this.iconLists.forEach((item,index) => {
        /* 8个一页 */
        const page = Math.floor(index/8);/* 除以8向下取整，就是获得0，就是第一页，当9是向下取整就是1，那么就是第二页 */
        if(!pages[page]){
          pages[page]=[]
        }
        pages[page].push(item)
      });
      return pages
    }
  }

}
</script>
<style lang='stylus' scoped>
@import '~styles/ellipsis.styl'
  .swiper-pagination
    bottom -3px  
  .icons
    margin-top .1rem 
    .icon
      position relative
      overflow hidden
      float left
      width 25%
      height 0
      padding-bottom 25%
      .icon-img
        position absolute
        top 0
        left 0
        right 0
        bottom .44rem
        box-sizing border-box
        .icon-img-content
          display block
          margin 0 auto
          height 100%
      .icon-desc
        position absolute
        left 0
        right 0
        bottom 0
        height .34rem
        line-height .34rem
        text-align center
        color red
        ellipsis()
</style>
